import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import vueJsx from '@vitejs/plugin-vue2-jsx'
import eslintPlugin from 'vite-plugin-eslint'
import legacy from '@vitejs/plugin-legacy'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig({
  plugins: [
    createVuePlugin(),
    vueJsx(),
    eslintPlugin({
      cache: false,
      include: ['src/**/*.js', 'src/**/*.vue'],
      exclude: ['node_modules/**']
    }),
    legacy({
      targets: ['defaults', 'ie >= 11', 'chrome 69', 'Chrome >= 49'], //需要兼容的目标列表，可以设置多个
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      renderLegacyChunks: true,
      polyfills: [
        'es.promise.all-settled',
        'es.object.entries',
        'es.symbol',
        'es.array.filter',
        'es.promise',
        'es.promise.finally',
        'es/map',
        'es/set',
        'es.array.for-each',
        'es.object.define-properties',
        'es.object.define-property',
        'es.object.get-own-property-descriptor',
        'es.object.get-own-property-descriptors',
        'es.object.keys',
        'es.object.to-string',
        'web.dom-collections.for-each',
        'esnext.global-this',
        'esnext.string.match-all'
      ],
      modernPolyfills: ['es.promise.all-settled', 'es.object.entries']
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions: ['.js', '.jsx', '.vue']
  },
  server: {
    open: true, //vite项目启动时自动打开浏览器
    hmr: true,
    port: 8066
  }
})
